/*
封装函数
*/
//存数据到本地
//一般需要转格式
export function setStorage(key, value){
    if(typeof value === "object" && value !== null){
        value = JSON.stringify(value);
    }
    window.localStorage.setItem(key,value);
}
export function getStorage(key, value){
    let data =  window.localStorage.getItem(key,value);
    
    try{
        if(key == 'userInfo'){
            data = JSON.parse(data)
           if(data.date  < new Date().getTime()) {
            window.localStorage.removeItem(key,value);
            data = null
            return data;
           }else{
            data.date += (3 * 24 * 60 * 60 * 1000 )
            setStorage(key,data)
            return data;
           }
        } else{
            return JSON.parse(data);;

        }
    }
    catch{
        return data;
    }
}
export function removeStorage(key, value){
    window.localStorage.removeItem(key,value);
}
export function removeAllStorage(key){
    window.localStorage.clear();
    
}